﻿/**
 * 表格的新建功能。
 */
Ext.define('Happy.table.action.New', {
    extend: 'Happy.table.action.ShowAction',
    alias: 'action.new',

    /**
     * @inheritdoc
     */
    defaultConfig: {
        itemId: 'new',
        iconCls: 'new-button',
        text: '新建',
        tableSelector: 'tablepanel'
    },

    /**
     * @inheritdoc
     */
    onContainerShow: function (container, table, record) {
        var me = this;

        var form = container.down('form');
        form.on('remotecreatesuccess', Ext.bind(me.onRemoteCreateSuccessHandler, me, [table], true));
        form.on('localcreatesuccess', Ext.bind(me.onLocalCreateSuccessHandler, me, [table], true));
        form.loadRecord(table.createRecord(record));
    },

    /**
     * 记录远程创建成功时的处理方法。
     * 
     * @private
     */
    onRemoteCreateSuccessHandler: function (form, record, table) {
        table.insertRecord(record);
    },

    /**
     * 记录本地创建成功时的处理方法。
     * 
     * @private
     */
    onLocalCreateSuccessHandler: function (form, record, table) {
        table.insertRecord(record);
    }
});